//
//  Utils.m
//  NhomTuan
//
//  Created by Buffalo on 1/28/15.
//  Copyright (c) 2015 Buffalo. All rights reserved.
//

#import "AppUtils.h"
#import "AppManager.h"
@implementation AppUtils

// Lay danh sach trong file plist >> NSArray
+ (NSArray *)getArrayDataInPlist:(NSString *)plistFile withKey:(NSString *)key {
    NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:plistFile];
    NSArray *data = [NSArray arrayWithArray:[plist objectForKey:key]];
    return data;
}

// Copyfile
+ (void)copyFile:(NSString *)filePath toPath:(NSString *)path {
    NSError *error;
    BOOL success = [[NSFileManager defaultManager] copyItemAtPath:filePath toPath:path error:&error];
    if (!success) {
        NSLog(@"Loi copy file: %@", error.description);
    }
}

//kiem tra ton tai file hay thu muc
+ (BOOL)checkFileOrDirExits:(NSString *)path isDir:(BOOL)isDir {
    BOOL isExits;
    if (isDir) {
        isExits = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isExits];
    } else {
        isExits = [[NSFileManager defaultManager] fileExistsAtPath:path];
    }
    return isExits;
}

// Lay bai hat voi song-code >> NSDictionary
+ (NSDictionary *)getSongWithCode:(NSString *)songCode {
    for (NSDictionary *enSong in [AppManager defaultmanager].enSongList) {
        NSString *code = [enSong objectForKey:KEY_SONG_CODE];
        if ([code isEqualToString:songCode]) {
            return enSong;
        }
    }
    for (NSDictionary *viSong in [AppManager defaultmanager].viSongList) {
        NSString *code = [viSong objectForKey:KEY_SONG_CODE];
        if ([code isEqualToString:songCode]) {
            return viSong;
        }
    }
    return nil;
}

+ (NSDictionary *)getSingerWithId:(NSString *)singerId {
    for (NSDictionary *singer in [AppManager defaultmanager].singerList) {
        NSString *iden = [singer objectForKey:KEY_SINGER_ID];
        if ([iden isEqualToString:singerId]) {
            return singer;
        }
    }
    return nil;
}

+ (BOOL)getLikeStatusWithSongCode:(NSString *)songCode {
    for (NSString *code in [AppManager defaultmanager].favorSongList) {
        if ([code isEqualToString:songCode]) {
            return true; 
        }
    }
    return false; 
}

// Minh Phuong
// Lay danh sach bai hat cua ca sy theo singerId
// songList la NSArray gom cac items khai bao theo doi tuong Song.h
+ (NSArray *)getSingerSongList:(NSString *)singerId {
    NSMutableArray *singerSongList = [[NSMutableArray alloc] init];

    for (NSDictionary *enSong in [AppManager defaultmanager].enSongList) {
        NSString *iden = [enSong objectForKey:KEY_SINGER_ID];
        if ([iden isEqualToString:singerId]) {
            [singerSongList addObject:enSong];
        }
    }
    for (NSDictionary *viSong in [AppManager defaultmanager].viSongList) {
        NSString *iden = [viSong objectForKey:KEY_SINGER_ID];
        if ([iden isEqualToString:singerId]) {
            [singerSongList addObject:viSong];
        }
    }

    return singerSongList;
}

// Hoang An
// them bai hat yeu thich vao favorSongList theo songCode
// Cau truc favorSongList la MutableArray, cac Items khai bao theo doi tuong Song.h)
+ (void)addFavorSong:(NSString *)songCode {
}

//Hoang An
//Xoa bai hat yeu thich theo songcode trong favorSongList
+ (void)removeFavorSong:(NSString *)songCode {
}

//==================
+ (UIColor *)greenColor {
    //61 180 103
    UIColor *color = [UIColor colorWithRed:(float)61 / 255 green:(float)180 / 255 blue:(float)103 / 255 alpha:1.0f];
    return color;
}

@end
